package shen.yue.example.one.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import shen.yue.example.one.R;

/**
 * Created by jiangzhuolei on 2017/8/2.
 */

public class Activity3 extends Activity {

    private FrameLayout edwordLayout;// 包含文字的外层区域
    private LinearLayout container;// 文字跟随移动的控件区域
    private int edtextX, edtextY;// 文字随手指移动时的坐标
    private EditText edMyword;// 输入文字的控件

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity3);
        initUI();
    }

    private void initUI()
    {
        edwordLayout = (FrameLayout) findViewById(R.id.edwordsLayout);
        container = (LinearLayout) findViewById(R.id.container);
        edMyword = (EditText) findViewById(R.id.edmyWords);
        edMyword.setHint("I'M EDITTEXT!");
        edMyword.setTextSize(16);
        edMyword.setTextColor(Color.BLUE);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
                edtextX = (int) event.getRawX();
                edtextY = (int) event.getRawY();
                break;
            }
            case MotionEvent.ACTION_MOVE:
            {
                int x2 = (int) event.getRawX();
                int y2 = (int) event.getRawY();
                //让包含edittext的linearlayout随手指的移动而改变位置
                container.scrollBy(edtextX - x2, edtextY - y2);
                edtextX = x2;
                edtextY = y2;
                break;
            }
            case MotionEvent.ACTION_UP:
            {
                break;
            }
        }
        return true;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        //getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
